package ${sourceBasePackage}.controller<#if sourceIncludeModule == 'Y'>.${moduleName}</#if>;

import com.wn.common.api.ApiResult;
import ${sourceBasePackage}.dto<#if sourceIncludeModule == 'Y'>.${moduleName}</#if>.${entityName}Dto;
import ${sourceBasePackage}.dto<#if sourceIncludeModule == 'Y'>.${moduleName}</#if>.${entityName}SearchDto;
import ${sourceBasePackage}.service<#if sourceIncludeModule == 'Y'>.${moduleName}</#if>.${entityName}Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * ${description}Controller
 * @author ${author}
 */
@Api(tags="${description}")
@RestController
@RequestMapping("/${entityName?uncap_first}")
public class ${entityName}Controller {

	private static final Logger log = LoggerFactory.getLogger(${entityName}Controller.class);

	@Autowired
	private ${entityName}Service ${entityName?uncap_first}Service;

	/**
	 * 分页查询
	 * @param ${entityName?uncap_first}SearchDto
	 * @return
	 */
	@ApiOperation(value="分页查询")
	@PostMapping("/getListByPage")
	public ApiResult getListByPage(@RequestBody ${entityName}SearchDto ${entityName?uncap_first}SearchDto) {
		return ApiResult.success(${entityName?uncap_first}Service.getListByPage(${entityName?uncap_first}SearchDto));
	}

	/**
	 * 通过id查询
	 * @param ${pkPropertyName}
	 * @return
	 */
	@ApiOperation(value="通过id查询")
	@GetMapping("/getById")
	public ApiResult getById(${pkPropertyType} ${pkPropertyName}) {
		return ApiResult.success(${entityName?uncap_first}Service.getById(${pkPropertyName}));
	}

	/**
	 * 新增
	 * @param ${entityName?uncap_first}Dto
	 * @return
	 */
	@ApiOperation(value="新增")
	@PostMapping("/add")
	public ApiResult add(@RequestBody ${entityName}Dto ${entityName?uncap_first}Dto) {
		try {
			${entityName?uncap_first}Service.add(${entityName?uncap_first}Dto);
			return ApiResult.success();
		} catch (Exception e) {
			log.error("新增失败", e);
			return ApiResult.fail();
		}
	}

	/**
	 * 修改
	 * @param ${entityName?uncap_first}Dto
	 * @return
	 */
	@ApiOperation(value="修改")
	@PostMapping("/update")
	public ApiResult update(@RequestBody ${entityName}Dto ${entityName?uncap_first}Dto) {
		try {
			${entityName?uncap_first}Service.update(${entityName?uncap_first}Dto);
			return ApiResult.success();
		} catch (Exception e) {
			log.error("修改失败", e);
			return ApiResult.fail();
		}
	}

	/**
	 * 删除
	 * @param ${pkPropertyName}
	 * @return
	 */
	@ApiOperation(value="删除")
	@DeleteMapping("/delete")
	public ApiResult delete(${pkPropertyType} ${pkPropertyName}) {
		try {
			${entityName?uncap_first}Service.delete(${pkPropertyName});
			return ApiResult.success();
		} catch (Exception e) {
			log.error("删除失败", e);
			return ApiResult.fail();
		}
	}

}
